package xx.iverson.controller;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xx.iverson.util.CaptchaUtil;

import java.awt.image.BufferedImage;
import java.io.IOException;
/**
 * xx.iverson.controller.CaptchaController
 * 描述：验证码控制器
 * on 2025/6/18-下午3:24
 *
 * @author weijx
 */
@RestController
@RequestMapping("/api/captcha")
public class CaptchaController {

    @GetMapping
    public void getCaptcha(HttpServletRequest request, HttpServletResponse response) throws IOException {
        // 设置响应头
        response.setContentType("image/png");
        response.setHeader("Cache-Control", "no-cache, no-store");
        response.setHeader("Pragma", "no-cache");

        // 生成验证码图片
        BufferedImage captchaImage = CaptchaUtil.generateCaptchaImage(request);

        // 输出图像
        javax.imageio.ImageIO.write(captchaImage, "PNG", response.getOutputStream());
    }
}
